using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class Player_Nav : MonoBehaviour
{
    private NavMeshAgent agent;
    public GameObject starry;
    // Start is called before the first frame update
    void Start()
    {
        agent = GetComponent<NavMeshAgent>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonUp(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                if (!(hit.collider.name == "Plane"))
                {
                    return;
                }
                Vector3 pos = hit.point;
                Instantiate(starry.gameObject, pos+new Vector3(0,1
                    ,0), Quaternion.identity);
                transform.LookAt(new Vector3(hit.point.x, transform.position.y, hit.point.z));
                agent.SetDestination(pos);
            }
        }
    }
}
